<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>string.Replace() 函数只会替换第一个项目</title>
</head>

<body>
</body>
<script>
  // 正则表达式的末尾添加 /g 来替换所有内容。
  "use strict"; {
    var example = "Potato potato";
    console.log(example.replace(/pot/, "tom"));
    // "tomato potato"
    console.log(example.replace(/pot/ig, "tom"));
    // "tomato tomato"
  };
</script>

</html>